
import Vue from 'vue'
import VueRouter from 'vue-router'

//0.
Vue.use(VueRouter)

// 1.路由组件
import { ErrorRoutes } from '@/views/ErrorPage/route'
import { LoginsRoute } from '@/views/Logins/route'
import { MainRoute } from '@/views/Main/route'
import { GoodsRoutes } from '@/views/Good/route'

// 2. 定义路由配置选项
const routes = [
  {
    path:"/",
    redirect:{name:'guide'}
  },
  {
    path:"/guide",
    name:'guide',
    component:()=>import('@/views/Guide/Guide.vue')
  },
  ...ErrorRoutes,
  ...LoginsRoute,
  ...MainRoute,
  ...GoodsRoutes,
  {
    path:"/search",
    name:'search',
    component:()=>import('@/views/Search/Search.vue')
  },
  {
    path:"*",
    redirect:'/404'
  }
 
]


// 3. 创建路由对象
const router = new VueRouter({
  mode:'history',
  base:"",
  routes,
  scrollBehavior(to,from,savePosition){ //页面跳转详情后返回还在之前滚动高度
    return savePosition;   // 滚动条高度 
 }
})

// 4. 暴露挂载
export default router